package com.yx.accountBook.common;

import com.yx.accountBook.user.vo.UserVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.crazycake.shiro.SerializeUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by lyj on 2015/12/17.
 */
public abstract class BaseController {

    /**
     * 获取当前登录用户的的信息
     * @return
     * @author lyj
     * @since 2015/12/17
     */
    public UserVo getUser() {
        Subject subject = SecurityUtils.getSubject();
        Map<String, Object> map = (Map<String, Object>) SerializeUtils.deserialize((byte[]) subject.getSession().getAttribute("user"));
        if(map !=null){
            //Long id, Long userId, String name, String account,Long role,List<String> subjectIds,String remark,String tel,String userPhoto
            return new UserVo((Long)map.get("id"),(Long)map.get("userId"),(String)map.get("name"),
                    (String)map.get("account"),(Long) map.get("role"),(List)map.get("subjectIds"),(String)map.get("remark"),(String)map.get("tel"),(String)map.get("userPhoto"));
        }
        return null;
    }

    public UserVo getUser1() {
        UserVo u = new UserVo();
        u.setId(2l);
        return u;
    }

}
